package org.project.product.android.pfe_fanta;

import org.project.product.android.pfe.fanta.R;
import org.project.product.android.pfe.fanta.adapter.DataManagerFacade;
import org.project.product.android.pfe.fanta.domain.User;
import org.project.product.android.pfe.fanta.util.Utils;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class UserActivity extends ActivityParent {

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		this.setContentView(R.layout.add_user);

	}

	public void addUser(View v) {

		final EditText matriculeEdit = (EditText) findViewById(R.id.edit_user_matricule);
		final EditText loginEdit = (EditText) findViewById(R.id.edit_user_login);
		final EditText passwordEdit = (EditText) findViewById(R.id.edit_user_password);
		final EditText codePin = (EditText) findViewById(R.id.edit_user_codepin);

		if (Utils.checkEditText(this, matriculeEdit, loginEdit, passwordEdit,
		        codePin)) {
			User user = new User();
			user.setMatricule(matriculeEdit.getText().toString());
			user.setLogin(loginEdit.getText().toString());
			user.setPassword(passwordEdit.getText().toString());
			user.setCodePin(codePin.getText().toString());
			DataManagerFacade.getInstance(this).saveUser(user);
			Toast.makeText(getApplicationContext(),
			        "User " + user.getLogin() + "P :" + user.getCodePin(),
			        Toast.LENGTH_SHORT).show();

			Utils.lancerActivity(this, Home.class);
		}
	}

}
